#include<iostream>
#include<map>

using namespace std;

int judge(char A,char B){
	if(A==B) return 0;
	else if(A=='C'&&B=='J') return 1;
	else if(A=='J'&&B=='B') return 1;
	else if(A=='B'&&B=='C') return 1;
	else{
		return -1;
	}
}

int main(){
	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	int wing_jia=0;
	int tie_jia=0;
	int lose_jia=0;
	map<char,int,less<char>> m1,m2;
	while(n--){
		char A,B;
		cin>>A>>B;
		if(judge(A,B)==1){
			wing_jia++;
			m1[A]++;
		}else if(judge(A,B)==0){
			tie_jia++;
		}else{
			lose_jia++;
			m2[B]++;
		}
	}

	cout<<wing_jia<<" "<<tie_jia<<" "<<lose_jia<<endl;
	cout<<lose_jia<<" "<<tie_jia<<" "<<wing_jia<<endl;
	int max_m1=0,max_m2=0;
	char char_m1,char_m2;
	for(auto i:m1){
		// cout<<i.first<<" "<<i.second<<endl;
		if(i.second>max_m1){
			max_m1=i.second;
			char_m1=i.first;
		}

	}
	if(max_m1>0) cout<<char_m1<<" ";
	if(max_m1==0) cout<<"B ";
	for(auto i:m2){
		// cout<<i.first<<" "<<i.second<<endl;
		if(i.second>max_m2){
			max_m2=i.second;
			char_m2=i.first;
		}
	}
	if(max_m2>0) cout<<char_m2<<endl;
	if(max_m2==0) cout<<"B"<<endl;
	return 0;
}